import java.util.ArrayList;

/**
 * @author a1615
 */
public class Tem {
    public static void main(String[] args) {
        // 1.案例一  集合合并 去重
        String str1 = "语文,数学,英语,法语,语文,德语,数学,阿拉伯语";
        String str2 = "语文,法语,体育,美术,德语";
        /*
         * 1.  定义方法 拆分字符串 存储到集合
         * 2.  定义方法 合并两个集合  把出现的所有科目合并到新的集合(不允许用set) 不允许用 contains()方法
         * */
        // ====================================================================================
        // 2.案例二
        String str = "刘备,关羽,刘诗诗,官匪匪,关菲菲,赵晕晕,赵云,王励勤,王力宏,李思思,汪峰峰";
        // 定义方法  统计  字符中出现的人名姓氏 共计 个数  以及  打印 相同姓氏集合


        Tool tool = new Tool();

        // 1.案例一
        ArrayList<String> arrayList = tool.stringSplitToArrayList(str1, ",");
        ArrayList<String> arrayList1 = tool.stringSplitToArrayList(str2, ",");
        //合并为arrayList
        arrayList.addAll(arrayList1);
        arrayList = tool.removalRepeatability(arrayList);
        System.out.println(arrayList);
        // ====================================================================================

        // 2.案例二
        arrayList = tool.stringSplitToArrayList(str, ",");
        arrayList = tool.removalRepeatability(arrayList);
        ArrayList<String> familyNameList = new ArrayList<>();
        for (String name : arrayList) {
            familyNameList.add(String.valueOf(name.charAt(0)));
        }
        familyNameList = tool.removalRepeatability(familyNameList);

        ArrayList<ArrayList<Integer>> familyNameListIndexName = new ArrayList<>();

        for (String familyName : familyNameList) {
            familyNameListIndexName.add(
                    tool.findCharForListOfPlace(arrayList, familyName.charAt(0), 0)
            );

        }

        //输出
        for (int i = 0; i < familyNameList.size(); i++) {
            System.out.print("姓氏：");
            System.out.println(familyNameList.get(i));
            for (int j = 0; j < familyNameListIndexName.get(i).size(); j++) {
                System.out.println(arrayList.get(
                        familyNameListIndexName.get(i).get(j)
                ));
            }
            System.out.println();
        }


        // ====================================================================================
    }
}

